﻿#region DaExcelsrvresult
/*----------------------------------------------------------------
// 文件名：DaExcelsrvresult.cs
// 功能描述：表dbo.ExcelSrvResult的数据访问层
//
// 
// 创建时间：2009-11-25 DtataAccess template . Ver 5.0.20090413
//
// 修改标识： 
// 修改描述： 
//----------------------------------------------------------------*/
using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Data;
using System.Globalization;
using System.Text;
using System.Data.Common;
using Microsoft.Practices.EnterpriseLibrary.Data;
using Microsoft.Practices.EnterpriseLibrary.Data.Sql;


using DocSrv.Model;
using DocSrv.Core;


namespace DocSrv.Dal
{
    ///可以继承更上层接口,IExcelsrvresult ,数据访问层基类DaBase，
    ///DaBase中包含了DbException异常处理静态方法
    public partial class DaExcelsrvresult : DaBase<MoExcelsrvresult>
    {
        #region SQL const
        internal const string TABLE_COLUMNS = " ExcelSrvResult.FILE_ID ,ExcelSrvResult.MARK_NAME ,ExcelSrvResult.MARK_VALUE ,ExcelSrvResult.CREATE_TIME ,ExcelSrvResult.DESCRIPTION ,ExcelSrvResult.REPORT_ID ,ExcelSrvResult.TSRC   ";

        internal const string SQL_INSERT = "INSERT INTO EXCELSRVRESULT (" + TABLE_COLUMNS + ") VALUES (@FileId,@MarkName,@MarkValue,@CreateTime,@Description,@ReportId,@Tsrc)";
        internal const string SQL_SELECT = "SELECT " + TABLE_COLUMNS + " FROM EXCELSRVRESULT  ";
        internal const string SQL_SELECT_ONE = SQL_SELECT + " WHERE FILE_ID=@FileId AND  MARK_NAME=@MarkName";

        internal const string SQL_EXIST = "SELECT COUNT(*) FROM EXCELSRVRESULT  WHERE FILE_ID=@FileId and  MARK_NAME=@MarkName  ";
        internal const string SQL_UPDATE = "UPDATE EXCELSRVRESULT SET MARK_VALUE=@MarkValue, CREATE_TIME=@CreateTime, DESCRIPTION=@Description, REPORT_ID=@ReportId, TSRC=@Tsrc WHERE FILE_ID=@FileId AND  MARK_NAME=@MarkName";

        internal const string SQL_DELETE_DEFAULT = "DELETE FROM EXCELSRVRESULT ";
        internal const string SQL_DELETE = "DELETE FROM EXCELSRVRESULT WHERE FILE_ID=@FileId AND  MARK_NAME=@MarkName";

        internal const string SQL_COUNT = "SELECT COUNT(*) FROM ExcelSrvResult ";
        #endregion

        #region Constructor

        /// <summary>
        /// 默认构造函数，使用配置文件中默认的数据库配置。
        /// </summary>
        public DaExcelsrvresult()
        {
            this.db = DatabaseFactory.CreateDatabase();
        }
        /// <summary>
        /// 使用指定的databaseName数据库配置。
        /// </summary>
        /// <param name="databaseName">配置文件中数据库的配置名称。</param>
        public DaExcelsrvresult(string databaseName)
        {
            this.db = DatabaseFactory.CreateDatabase(databaseName);
        }

        public DaExcelsrvresult(Database db)
        {
            this.db = db;
        }

        #endregion

        //以下是CRUD方法，每个方法都有引入外部事务的版本

        #region 构造器模块

        protected override MoExcelsrvresult ConstructT()
        {
            return new MoExcelsrvresult();
        }
        #endregion



        #region Add模块 Helper

        ///build the command object.It never throw exception.
        protected override DbCommand ConstructAddCommand(Database db)
        {
            DbCommand dbCommand = db.GetSqlStringCommand(SQL_INSERT);

            db.AddInParameter(dbCommand, "FileId", DbType.AnsiString);
            db.AddInParameter(dbCommand, "MarkName", DbType.AnsiString);
            db.AddInParameter(dbCommand, "MarkValue", DbType.String);
            db.AddInParameter(dbCommand, "CreateTime", DbType.DateTime);
            db.AddInParameter(dbCommand, "Description", DbType.String);
            db.AddInParameter(dbCommand, "ReportId", DbType.AnsiString);
            db.AddInParameter(dbCommand, "Tsrc", DbType.Int32);
            return dbCommand;
        }
        protected override DbCommand ConstructAddCommand(Database db, MoExcelsrvresult entity)
        {
            DbCommand dbCommand = db.GetSqlStringCommand(SQL_INSERT);
            db.AddInParameter(dbCommand, "FileId", DbType.AnsiString, entity.FileId);
            db.AddInParameter(dbCommand, "MarkName", DbType.AnsiString, entity.MarkName);
            db.AddInParameter(dbCommand, "MarkValue", DbType.String, entity.MarkValue);
            db.AddInParameter(dbCommand, "CreateTime", DbType.DateTime, entity.CreateTime);
            db.AddInParameter(dbCommand, "Description", DbType.String, entity.Description);
            db.AddInParameter(dbCommand, "ReportId", DbType.AnsiString, entity.ReportId);
            db.AddInParameter(dbCommand, "Tsrc", DbType.Int32, entity.Tsrc);
            return dbCommand;
        }

        protected override DbCommand PopulateAddCommandParameters(Database db, DbCommand addCmd, MoExcelsrvresult entity)
        {
            db.SetParameterValue(addCmd, "FileId", entity.FileId);
            db.SetParameterValue(addCmd, "MarkName", entity.MarkName);
            db.SetParameterValue(addCmd, "MarkValue", entity.MarkValue);
            db.SetParameterValue(addCmd, "CreateTime", entity.CreateTime);
            db.SetParameterValue(addCmd, "Description", entity.Description);
            db.SetParameterValue(addCmd, "ReportId", entity.ReportId);
            db.SetParameterValue(addCmd, "Tsrc", entity.Tsrc);
            return addCmd;
        }

        protected override DbCommand PopulateAddCommandParameters(Database db, DbCommand addCmd, DataRow row)
        {
            db.SetParameterValue(addCmd, "FileId", row["FileId"]);
            db.SetParameterValue(addCmd, "MarkName", row["MarkName"]);
            db.SetParameterValue(addCmd, "MarkValue", row["MarkValue"]);
            db.SetParameterValue(addCmd, "CreateTime", row["CreateTime"]);
            db.SetParameterValue(addCmd, "Description", row["Description"]);
            db.SetParameterValue(addCmd, "ReportId", row["ReportId"]);
            db.SetParameterValue(addCmd, "Tsrc", row["Tsrc"]);
            return addCmd;
        }

        #endregion

        #region Update模块 Helper

        protected override DbCommand ConstructUpdateCommand(Database db)
        {
            DbCommand dbCommand = db.GetSqlStringCommand(SQL_UPDATE);
            db.AddInParameter(dbCommand, "MarkValue", DbType.String);
            db.AddInParameter(dbCommand, "CreateTime", DbType.DateTime);
            db.AddInParameter(dbCommand, "Description", DbType.String);
            db.AddInParameter(dbCommand, "ReportId", DbType.AnsiString);
            db.AddInParameter(dbCommand, "Tsrc", DbType.Int32);
            db.AddInParameter(dbCommand, "FileId", DbType.AnsiString);
            db.AddInParameter(dbCommand, "MarkName", DbType.AnsiString);

            return dbCommand;
        }
        protected override DbCommand ConstructUpdateCommand(Database db, MoExcelsrvresult entity)
        {
            DbCommand dbCommand = db.GetSqlStringCommand(SQL_UPDATE);
            db.AddInParameter(dbCommand, "MarkValue", DbType.String, entity.MarkValue);
            db.AddInParameter(dbCommand, "CreateTime", DbType.DateTime, entity.CreateTime);
            db.AddInParameter(dbCommand, "Description", DbType.String, entity.Description);
            db.AddInParameter(dbCommand, "ReportId", DbType.AnsiString, entity.ReportId);
            db.AddInParameter(dbCommand, "Tsrc", DbType.Int32, entity.Tsrc);
            db.AddInParameter(dbCommand, "FileId", DbType.AnsiString, entity.FileId);
            db.AddInParameter(dbCommand, "MarkName", DbType.AnsiString, entity.MarkName);

            return dbCommand;
        }

        protected override DbCommand PopulateUpdateCommandParameters(Database db, DbCommand updateCmd, MoExcelsrvresult entity)
        {
            db.SetParameterValue(updateCmd, "MarkValue", entity.MarkValue);
            db.SetParameterValue(updateCmd, "CreateTime", entity.CreateTime);
            db.SetParameterValue(updateCmd, "Description", entity.Description);
            db.SetParameterValue(updateCmd, "ReportId", entity.ReportId);
            db.SetParameterValue(updateCmd, "Tsrc", entity.Tsrc);
            db.SetParameterValue(updateCmd, "FileId", entity.FileId);
            db.SetParameterValue(updateCmd, "MarkName", entity.MarkName);
            return updateCmd;
        }
        protected override DbCommand PopulateUpdateCommandParameters(Database db, DbCommand updateCmd, DataRow row)
        {
            db.SetParameterValue(updateCmd, "MarkValue", row["MarkValue"]);
            db.SetParameterValue(updateCmd, "CreateTime", row["CreateTime"]);
            db.SetParameterValue(updateCmd, "Description", row["Description"]);
            db.SetParameterValue(updateCmd, "ReportId", row["ReportId"]);
            db.SetParameterValue(updateCmd, "Tsrc", row["Tsrc"]);
            db.SetParameterValue(updateCmd, "FileId", row["FileId"]);
            db.SetParameterValue(updateCmd, "MarkName", row["MarkName"]);
            return updateCmd;
        }

        protected override void PrepareDataAdapterCommand(Database db, out DbCommand dbInsertCommand,
                             out DbCommand dbUpdateCommand, out DbCommand dbDeleteCommand)
        {
            dbInsertCommand = db.GetSqlStringCommand(SQL_INSERT);
            #region set insert cmd parameters
            db.AddInParameter(dbInsertCommand, "FileId", DbType.AnsiString, "FILE_ID", DataRowVersion.Current);
            db.AddInParameter(dbInsertCommand, "MarkName", DbType.AnsiString, "MARK_NAME", DataRowVersion.Current);
            db.AddInParameter(dbInsertCommand, "MarkValue", DbType.String, "MARK_VALUE", DataRowVersion.Current);
            db.AddInParameter(dbInsertCommand, "CreateTime", DbType.DateTime, "CREATE_TIME", DataRowVersion.Current);
            db.AddInParameter(dbInsertCommand, "Description", DbType.String, "DESCRIPTION", DataRowVersion.Current);
            db.AddInParameter(dbInsertCommand, "ReportId", DbType.AnsiString, "REPORT_ID", DataRowVersion.Current);
            db.AddInParameter(dbInsertCommand, "Tsrc", DbType.Int32, "TSRC", DataRowVersion.Current);
            #endregion
            dbUpdateCommand = db.GetSqlStringCommand(SQL_UPDATE);
            #region Set update cmd value parameters
            db.AddInParameter(dbUpdateCommand, "MarkValue", DbType.String, "MARK_VALUE", DataRowVersion.Current);
            db.AddInParameter(dbUpdateCommand, "CreateTime", DbType.DateTime, "CREATE_TIME", DataRowVersion.Current);
            db.AddInParameter(dbUpdateCommand, "Description", DbType.String, "DESCRIPTION", DataRowVersion.Current);
            db.AddInParameter(dbUpdateCommand, "ReportId", DbType.AnsiString, "REPORT_ID", DataRowVersion.Current);
            db.AddInParameter(dbUpdateCommand, "Tsrc", DbType.Int32, "TSRC", DataRowVersion.Current);
            #endregion
            #region set update cmd pk where parameters
            db.AddInParameter(dbUpdateCommand, "FileId", DbType.AnsiString, "FILE_ID", DataRowVersion.Current);
            db.AddInParameter(dbUpdateCommand, "MarkName", DbType.AnsiString, "MARK_NAME", DataRowVersion.Current);
            #endregion
            dbDeleteCommand = db.GetSqlStringCommand(SQL_DELETE);
            #region set delete cmd pk where parameters
            db.AddInParameter(dbDeleteCommand, "FileId", DbType.AnsiString, "FILE_ID", DataRowVersion.Current);
            db.AddInParameter(dbDeleteCommand, "MarkName", DbType.AnsiString, "MARK_NAME", DataRowVersion.Current);
            #endregion
        }
        #endregion

        #region Delete模块 Helper

        protected override DbCommand ConstructDeleteCommand(Database db)
        {
            DbCommand dbCommand = db.GetSqlStringCommand(SQL_DELETE);

            db.AddInParameter(dbCommand, "FileId", DbType.AnsiString);
            db.AddInParameter(dbCommand, "MarkName", DbType.AnsiString);

            return dbCommand;
        }
        protected override DbCommand ConstructDeleteCommand(Database db, MoExcelsrvresult entity)
        {
            DbCommand dbCommand = db.GetSqlStringCommand(SQL_DELETE);

            db.AddInParameter(dbCommand, "FileId", DbType.AnsiString, entity.FileId);
            db.AddInParameter(dbCommand, "MarkName", DbType.AnsiString, entity.MarkName);

            return dbCommand;
        }

        protected override DbCommand ConstructDeleteCommandForWhere(Database db, string where)
        {
            return db.GetSqlStringCommand(SQL_DELETE_DEFAULT + where);
        }

        protected override DbCommand PopulateDeleteCommandParameters(Database db, DbCommand deleteCmd, MoExcelsrvresult entity)
        {
            db.SetParameterValue(deleteCmd, "FileId", entity.FileId);
            db.SetParameterValue(deleteCmd, "MarkName", entity.MarkName);
            return deleteCmd;
        }

        protected override DbCommand PopulateDeleteCommandParameters(Database db, DbCommand deleteCmd, DataRow row)
        {
            db.SetParameterValue(deleteCmd, "FileId", row["FileId"]);
            db.SetParameterValue(deleteCmd, "MarkName", row["MarkName"]);
            return deleteCmd;
        }

        #endregion helper

        #region Query模块 Helper

        protected override DbCommand ConstructQueryCommand(string condition)
        {
            return db.GetSqlStringCommand(SQL_SELECT + condition);
        }

        #endregion

        #region GetEntity(s)模块 Helper

        protected override DbCommand ConstructSelectOneCommand(Database db, MoExcelsrvresult entity)
        {
            DbCommand dbCommand = db.GetSqlStringCommand(SQL_SELECT_ONE);

            db.AddInParameter(dbCommand, "FileId", DbType.AnsiString, entity.FileId);
            db.AddInParameter(dbCommand, "MarkName", DbType.AnsiString, entity.MarkName);
            return dbCommand;
        }

        protected override void PopulateEntityByDataReader(IDataReader reader, ref MoExcelsrvresult entity)
        {
            if (!reader.IsDBNull(0)) entity.FileId = reader.GetString(0);
            if (!reader.IsDBNull(1)) entity.MarkName = reader.GetString(1);
            if (!reader.IsDBNull(2)) entity.MarkValue = reader.GetString(2);
            if (!reader.IsDBNull(3)) entity.CreateTime = reader.GetDateTime(3);
            if (!reader.IsDBNull(4)) entity.Description = reader.GetString(4);
            if (!reader.IsDBNull(5)) entity.ReportId = reader.GetString(5);
            if (!reader.IsDBNull(6)) entity.Tsrc = reader.GetInt32(6);
        }



        protected override DbCommand ConstructSelectConditionCommand(Database db, string condition)
        {
            return db.GetSqlStringCommand(SQL_SELECT + condition);
        }

        #endregion

        #region Count模块 Helper

        protected override DbCommand ConstructCountCommand(Database db)
        {
            return db.GetSqlStringCommand(SQL_COUNT);
        }

        protected override DbCommand ConstructCountConditionCommand(Database db, string condition)
        {
            return db.GetSqlStringCommand(SQL_COUNT + condition);
        }

        #endregion

        #region IsExist模块 Helper

        protected override DbCommand ConstructIsExistCommand(Database db, MoExcelsrvresult entity)
        {
            DbCommand dbCommand = db.GetSqlStringCommand(SQL_EXIST);
            db.AddInParameter(dbCommand, "FileId", DbType.AnsiString, entity.FileId);
            db.AddInParameter(dbCommand, "MarkName", DbType.AnsiString, entity.MarkName);
            return dbCommand;
        }

        #endregion



    }
}
#endregion

